import { createSlice } from '@reduxjs/toolkit'

const config = window.APP_Config;
const configSlice = createSlice(
    {
        name: "config",
        initialState: {
            defaultOpenKeys: [sessionStorage.getItem('defaultOpenKeys') || config.defaultOpenKeys],
            defaultSelectedKeys: [sessionStorage.getItem('defaultSelectedKeys') || config.home],
            menuTree:[],
            selected_menu: {},
            isLoading:false,
           
        },
        reducers: {
           
            //设置全局加载
            set_isLoading(state,action){
                state.isLoading=action.payload;
            },
            set_defaultOpenKeys(state, action) {
                state.defaultOpenKeys = [action.payload];
                sessionStorage.setItem('defaultOpenKeys', action.payload);
            },
            set_defaultSelectedKeys(state, action) {
                state.defaultSelectedKeys = [action.payload];
                sessionStorage.setItem('defaultSelectedKeys', action.payload);
            },
            set_selected_menu(state, action) {
                state.selected_menu = JSON.parse(action.payload);
            },
            set_menu_tree(state,action){
                state.menuTree=action.payload;
            }

        }
    }
)

export const {set_isLoading, set_selected_key,set_menu_tree, set_defaultSelectedKeys, set_defaultOpenKeys, set_selected_menu } = configSlice.actions



export default configSlice.reducer